Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

socks

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

socks

Fully featured SOCKS proxy client supporting SOCKSv4, SOCKSv4a, and SOCKSv5. Includes Bind and Associate functionality.

  • 2.8.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22M
increased by2.38%
Maintainers
1
Weekly downloads
 
Created

What is socks?

The 'socks' npm package is a comprehensive Node.js library for working with SOCKS proxies. It supports SOCKS v4, v4a, and v5 protocols and can be used to create both SOCKS proxy clients and servers. It allows for proxying TCP and UDP connections, handling DNS lookups, and provides a way to work with different authentication methods.

What are socks's main functionalities?

Creating a SOCKS client

This code sample demonstrates how to create a SOCKS client that connects to a specified destination through a SOCKS proxy server.

const { SocksClient } = require('socks');

const options = {
  proxy: {
    host: 'host', // ipv4, ipv6, or hostname
    port: 1080,
    type: 5 // Proxy version (4, 5)
  },
  command: 'connect',
  destination: {
    host: 'destinationHost',
    port: 80
  }
};

SocksClient.createConnection(options, (err, info) => {
  if (err) {
    console.log(err);
    return;
  }
  const socket = info.socket;
  console.log('Connected to server through SOCKS proxy');
});

Creating a SOCKS server

This code sample shows how to create a SOCKS server that listens for incoming connections and can handle custom authentication.

const socks = require('socks').SocksServer;

const server = new socks({
  proxy: {
    ipaddress: 'localhost',
    port: 1080,
    type: 5
  },
  authenticate: function(username, password, socket, callback) {
    // Custom authentication logic
    callback();
  }
});

server.listen();

server.on('proxyConnect', (info, destinationSocket) => {
  console.log(`Accepted connection to ${info.host}:${info.port}`);
});

Handling UDP connections

This code sample illustrates how to handle UDP connections through a SOCKS proxy using the 'associate' command.

const { SocksClient } = require('socks');

const options = {
  proxy: {
    host: 'host',
    port: 1080,
    type: 5
  },
  command: 'associate',
  destination: {
    host: '0.0.0.0', // The local interface to bind for UDP association
    port: 0 // A random port will be used
  }
};

SocksClient.createConnection(options, (err, info) => {
  if (err) {
    console.log(err);
    return;
  }
  const udpSocket = info.socket;
  console.log('UDP association has been established.');
});

Other packages similar to socks

Keywords

FAQs

Package last updated on 10 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc